﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DispatchAssist.BusinessLogical.DAL;
using CarolLib;
using DispatchAssist.BusinessLogical.Model;

namespace DispatchAssist.BusinessLogical.BLL
{
    public class EarlyWarningManager
    {
        #region Members

        private IDataProvider _provider;
        static log4net.ILog Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
      //  private int CacheTime = 3600;
        private readonly static string ALlEarlyWarningCacheKey = "Cache_EarlyTime";
        public static readonly EarlyWarningManager Instance = new EarlyWarningManager();
        #endregion



        public EarlyWarningManager()
        {
            _provider = new SqlDataProvider();
        }



        #region Method Body


        public List<EarlyWarning> GetAllEarlyWarningRecords()
        {
            try
            {
                //List<EarlyWarning> list;
                //if (!CacheHelper.TryGet<List<EarlyWarning>>(ALlEarlyWarningCacheKey, out list))
                //{
                //    list = _provider.GetAllEarlyWarningRecords();
                //    CacheHelper.Insert(ALlEarlyWarningCacheKey, list, CacheTime);
                //}
                //return list;

                return CommonCacheData.CacheET.InitList;

            }
            catch (Exception e)
            {
                Logger.Error("EarlyWarningManager. GetAllEarlyWarningRecords() " + e.Message);
                return null;
            }

        }

        public bool CreateEarlyWarning(EarlyWarning EarlyWarning)
        {
            try
            {
                if (_provider.CreateEarlyWarning(EarlyWarning))
                {
                    CacheHelper.Remove(ALlEarlyWarningCacheKey);
                    return true;
                }
                return false;
            }
            catch (Exception e)
            {
                Logger.Error("EarlyWarningManager. CreateEarlyWarning() " + e.Message);
                return false;
            }
        }

        public bool UpdateEarlyWarning(EarlyWarning EarlyWarning)
        {
            try
            {
                if (_provider.UpdateEarlyWarning(EarlyWarning))
                {
                    CacheHelper.Remove(ALlEarlyWarningCacheKey);
                    return true;
                }
                return false;
            }
            catch (Exception e)
            {
                Logger.Error("EarlyWarningManager. UpdateEarlyWarning() " + e.Message);
                return false;
            }
        }
        public bool DeleteEarlyWarning(Guid EarlyWarningID)
        {

            try
            {
                if (_provider.DeleteEarlyWarning(EarlyWarningID))
                {
                    CacheHelper.Remove(ALlEarlyWarningCacheKey);
                    return true;
                }
                return false;
            }
            catch (Exception e)
            {
                Logger.Error("EarlyWarningManager. DeleteEarlyWarning() " + e.Message);
                return false;
            }
        }


        #endregion

    }
}
